---
title: News API
sidebarTitle: News API
---

In this section, we present how to connect News API to MindsDB.

[News API](https://newsapi.org/) is a simple HTTP REST API for searching and retrieving live articles from all over the web.

Data from News API can be utilized within MindsDB for model training and predictions.

## Prerequisites

Before proceeding, ensure the following prerequisites are met:

1. Install MindsDB [locally via Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or use [MindsDB Cloud](https://cloud.mindsdb.com/).
2. To connect News API to MindsDB, install the required dependencies following [this instruction](/setup/self-hosted/docker#install-dependencies).
3. Install or ensure access to News API.

## Connection

This handler is implemented using the [newsapi-python](https://newsapi.org/docs/client-libraries/python) library.

The required arguments to establish a connection are as follows:

* `api_key` News API key to use for authentication.

<Tip>
Check out [this guide](https://newsapi.org/docs/authentication) on how to create the API key.

It is recommended to use the API key to avoid the `API rate limit exceeded` error.
</Tip>

Here is how to connect News API to MindsDB:

```sql
CREATE DATABASE newsAPI
WITH ENGINE = 'newsapi'
PARAMETERS = {
	"api_key": "Your api key"
};
```

## Usage

Simple Search for recent articles:

```sql
SELECT *
FROM newsAPI.article
WHERE query = 'Python';
```

Advanced search for recent articles per specific sources between dates:

```sql
SELECT *
FROM newsAPI.article
WHERE query = 'Python'
AND sources="bbc-news"
AND publishedAt >= "2021-03-23" AND  publishedAt <= "2023-04-23"
LIMIT 4;
```

<Info>
For more information about available actions and development plans, visit [this page](https://github.com/mindsdb/mindsdb/blob/staging/mindsdb/integrations/handlers/newsapi_handler/README.md).
</Info>
